<?php defined('SYSPATH') or die('No direct script access.');

// Пользователи
class Model_Users
{
	public function __construct()
	{
	}
	
	public function get_users()
	{
		echo '123321';
		die();
	}
	
	public function get_user($user_id)
	{
		
	}
	
	public function add_user($user)
	{		
		if(!$user)
			return false;
		
		$user = ORM::factory('user')
				->create_user($user, array(
					'username',
					'password',
					'email'            
		));

		$user->add('roles', ORM::factory('role', array('name' => 'login')));
		
		return $user;
	}
	
	public function update_user($user)
	{
        $columns = array('username', 'email');
        
        if($user['password'])
            $columns[] = 'password';
        
		$user = ORM::factory('user')
				->where('id', '=', $user['id'])
				->find()
				->update_user($user, $columns);
		
		return $user;
	}
	
	public function delete_user($user_id)
	{
		$user = ORM::factory('user')
				->where('id', '=', $user_id)
				->find()
				->delete();
		
		return true;
	}
} // End Users